package GUI;

import Controladores.ControladorCompetencia;
import Controladores.ControladorDisciplina;
import Controladores.ControladorEspacioDeportivo;
import Controladores.ControladorEvento;
import Logico.Competencia;
import Logico.Disciplina;
import Logico.EspacioDeportivo;
import Logico.Evento;
import Logico.Usuario;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class CompetenciaGUI extends javax.swing.JPanel {

    ControladorEvento controladorEvento;
    ControladorDisciplina controladorDisciplina;
    ControladorEspacioDeportivo controladorEspacioDeportivo;
    ControladorCompetencia controladorCompetencia;
    EspacioDeportivo espacio;
    Disciplina disciplina;
    Evento evento;
    int idCompetencia;
    int idEvento;
    int idDisciplina;
    int idEspacio;
    String nombre;
    String descripcion;
    Date fecha;
    String hora;
    String tipoPuntaje;
    int cantidadVip;
    int cantidadPlatino;
    int cantidadGeneral;
    int cantidadAEliminatoria;
    String imagenpodio;
    List<Evento> listaEventos;
    List<Disciplina> listaDisciplinas;
    List<EspacioDeportivo> listaEspacios;
    List<Competencia> listaCompetencias;
    int indice;

    public CompetenciaGUI() {
        initComponents();
        controladorEvento = new ControladorEvento();
        listaEventos = controladorEvento.listarEventos();
        controladorDisciplina = new ControladorDisciplina();
        listaDisciplinas = controladorDisciplina.listardisciplinas();
        controladorEspacioDeportivo = new ControladorEspacioDeportivo();
        listaEspacios = controladorEspacioDeportivo.listarEspacioDeportivos();
        controladorCompetencia = new ControladorCompetencia();
        inicializarCampoEventos();
        inicializarCampoDisciplinas();
        inicializarCampoEspacios();
        if (!listaEventos.isEmpty()) {
            inicializarListaCompetencias(indice);
        }
        idEvento = 0;
        idDisciplina = 0;
        idEspacio = 0;
        idCompetencia = 0;

        indice = 0;
    }

    void inicializarCampoEventos() {
        if (!listaEventos.isEmpty()) {
            for (int i = 0; i < listaEventos.size(); i++) {
                campoEventos.addItem(listaEventos.get(i).getNombre());
            }
            idEvento = listaEventos.get(0).getIdevento();
            evento = controladorEvento.buscar(idEvento);
        }
    }

    void inicializarCampoDisciplinas() {
        if (!listaDisciplinas.isEmpty()) {
            for (int i = 0; i < listaDisciplinas.size(); i++) {
                campoDisciplinas.addItem(listaDisciplinas.get(i).getNombre());
            }
            idDisciplina = listaDisciplinas.get(0).getIddisciplina();
            disciplina = controladorDisciplina.buscar(idDisciplina);
        }
    }

    void inicializarCampoEspacios() {
        if (!listaEspacios.isEmpty()) {
            for (int i = 0; i < listaEspacios.size(); i++) {
                campoEspacios.addItem(listaEspacios.get(i).getNombre());
            }
            idEspacio = listaEspacios.get(0).getIdespacioDeportivo();
            espacio = controladorEspacioDeportivo.buscar(idEspacio);
        }
    }

    void inicializarListaCompetencias(int idE) {
        listaCompetencias = controladorCompetencia.buscarPorEvento(idE);
        System.out.println("Hay competencias?: "+listaCompetencias.isEmpty());
        if (!listaCompetencias.isEmpty()) {
            inicializarTabla();
        }
    }

    public void inicializarTabla() {
        tablaCompetencias.removeAll();
        DefaultTableModel modelo = (DefaultTableModel) tablaCompetencias.getModel();
        modelo.setRowCount(0);

        for (int i = 0; i < listaCompetencias.size(); i++) {
            String temp[] = new String[12];

            temp[0] = listaCompetencias.get(i).getIdcompetencia() + "";
            temp[1] = listaCompetencias.get(i).getDisciplinaIddisciplina() + "";
            temp[2] = listaCompetencias.get(i).getNombre() + "";
            temp[3] = listaCompetencias.get(i).getDescripcion() + "";
            temp[4] = listaCompetencias.get(i).getTipoPuntaje() + "";
            temp[5] = listaCompetencias.get(i).getCantidadAEliminatoria() + "";
            temp[6] = listaCompetencias.get(i).getFecha().toString() + "";
            temp[7] = listaCompetencias.get(i).getHora() + "";
            temp[8] = listaCompetencias.get(i).getIdespacioDeportivo() + "";
            temp[9] = listaCompetencias.get(i).getCantidadVip() + "";
            temp[10] = listaCompetencias.get(i).getCantidadPlatino() + "";
            temp[11] = listaCompetencias.get(i).getCantidadGeneral() + "";


            Object nuevo[] = null;
            modelo.addRow(nuevo);
            tablaCompetencias.setModel(modelo);
            for (int j = 0; j < temp.length; j++) {
                tablaCompetencias.setValueAt(temp[j], i, j);
            }
        }

        if (listaCompetencias.size() > 0) {
            indice = 0;
            actualizarFormulario();
        }

    }

    public void actualizarFormulario() {
        idCompetencia = listaCompetencias.get(indice).getIdcompetencia();
        campoId.setText(idCompetencia + "");
        nombre = listaCompetencias.get(indice).getNombre();
        campoNombre.setText(nombre);
        descripcion = listaCompetencias.get(indice).getDescripcion();
        campoDescripcion.setText(descripcion);
        fecha = listaCompetencias.get(indice).getFecha();
        campoFecha.setDate(fecha);
        hora = listaCompetencias.get(indice).getHora();
        campoHora.setText(hora);
        cantidadAEliminatoria = listaCompetencias.get(indice).getCantidadAEliminatoria();
        campoEliminatoria.setText(cantidadAEliminatoria + "");
        tipoPuntaje = listaCompetencias.get(indice).getTipoPuntaje();
        campoPuntaje.setText(tipoPuntaje);
        cantidadVip = listaCompetencias.get(indice).getCantidadVip();
        campoVIP.setText(cantidadVip + "");
        cantidadPlatino = listaCompetencias.get(indice).getCantidadPlatino();
        campoPlatino.setText(cantidadPlatino + "");
        cantidadGeneral = listaCompetencias.get(indice).getCantidadGeneral();
        campoGeneral.setText(cantidadGeneral + "");
        espacio = listaCompetencias.get(indice).getIdespacioDeportivo();
        idEspacio = espacio.getIdespacioDeportivo();
        campoEspacios.setSelectedItem(espacio.getNombre());
        disciplina = listaCompetencias.get(indice).getDisciplinaIddisciplina();
        idDisciplina = disciplina.getIddisciplina();
        campoDisciplinas.setSelectedItem(disciplina.getNombre());
    }

    public void limpiarFormulario() {
        idCompetencia = 0;
        campoId.setText(idCompetencia + "");
        nombre = "";
        campoNombre.setText(nombre);
        descripcion = "";
        campoDescripcion.setText(descripcion);
        fecha = new Date();
        campoFecha.setDate(fecha);
        hora = "";
        campoHora.setText(hora);
        cantidadAEliminatoria = 0;
        campoEliminatoria.setText(cantidadAEliminatoria + "");
        tipoPuntaje = "";
        campoPuntaje.setText(tipoPuntaje);
        cantidadVip = 0;
        campoVIP.setText(cantidadVip + "");
        cantidadPlatino = 0;
        campoPlatino.setText(cantidadPlatino + "");
        cantidadGeneral = 0;
        campoGeneral.setText(cantidadGeneral + "");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        campoPuntaje = new javax.swing.JTextField();
        campoDescripcion = new javax.swing.JTextField();
        campoNombre = new javax.swing.JTextField();
        campoId = new javax.swing.JTextField();
        botonGuardar = new javax.swing.JButton();
        botonActualizar = new javax.swing.JButton();
        botonEliminar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaCompetencias = new javax.swing.JTable();
        botonAnterior = new javax.swing.JButton();
        botonSiguiente = new javax.swing.JButton();
        botonLimpiar = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        campoEliminatoria = new javax.swing.JTextField();
        campoGeneral = new javax.swing.JTextField();
        campoPlatino = new javax.swing.JTextField();
        campoVIP = new javax.swing.JTextField();
        panelPodio = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        botonCargar = new javax.swing.JButton();
        campoHora = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        campoEventos = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        campoEspacios = new javax.swing.JComboBox();
        campoDisciplinas = new javax.swing.JComboBox();
        campoFecha = new com.toedter.calendar.JDateChooser();

        jLabel1.setText("Identificador");

        jLabel2.setText("Nombre");

        jLabel3.setText("Descripcion");

        jLabel4.setText("Puntaje");

        jLabel5.setText("Hora");

        campoId.setEditable(false);

        botonGuardar.setText("Guardar");
        botonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonGuardarActionPerformed(evt);
            }
        });

        botonActualizar.setText("Actualizar");
        botonActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonActualizarActionPerformed(evt);
            }
        });

        botonEliminar.setText("Eliminar");
        botonEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonEliminarActionPerformed(evt);
            }
        });

        tablaCompetencias.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Identificador", "Disciplina", "Nombre", "Descripción", "Puntaje", "Eliminatoria", "Fecha", "Hora", "Espacio", "VIP", "Platino", "General"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tablaCompetencias);

        botonAnterior.setText("<<");
        botonAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAnteriorActionPerformed(evt);
            }
        });

        botonSiguiente.setText(">>");
        botonSiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonSiguienteActionPerformed(evt);
            }
        });

        botonLimpiar.setText("Limpiar");
        botonLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonLimpiarActionPerformed(evt);
            }
        });

        jLabel6.setText("VIP");

        jLabel7.setText("Platino");

        jLabel8.setText("General");

        jLabel9.setText("Eliminatoria");

        jLabel10.setText("Fecha");

        panelPodio.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout panelPodioLayout = new javax.swing.GroupLayout(panelPodio);
        panelPodio.setLayout(panelPodioLayout);
        panelPodioLayout.setHorizontalGroup(
            panelPodioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 167, Short.MAX_VALUE)
        );
        panelPodioLayout.setVerticalGroup(
            panelPodioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        jLabel11.setText("Podio");

        botonCargar.setText("Cargar");

        jLabel13.setText("Evento");

        campoEventos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoEventosActionPerformed(evt);
            }
        });

        jLabel14.setText("Espacio");

        jLabel15.setText("Disciplina");

        campoEspacios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoEspaciosActionPerformed(evt);
            }
        });

        campoDisciplinas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoDisciplinasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(botonGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(botonActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel13)
                                    .addComponent(jLabel14))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(campoPuntaje, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(campoDescripcion, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(campoNombre, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(campoId, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(campoHora, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(campoEventos, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(campoEspacios, javax.swing.GroupLayout.Alignment.LEADING, 0, 80, Short.MAX_VALUE))))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(botonEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(botonLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 158, Short.MAX_VALUE)
                                .addComponent(botonAnterior)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(botonSiguiente))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(jLabel15)
                                        .addGap(18, 18, 18)
                                        .addComponent(campoDisciplinas, 0, 83, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel9)
                                            .addComponent(jLabel10)
                                            .addComponent(jLabel8)
                                            .addComponent(jLabel7)
                                            .addComponent(jLabel6))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(campoEliminatoria)
                                            .addComponent(campoVIP, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                                            .addComponent(campoPlatino)
                                            .addComponent(campoGeneral)
                                            .addComponent(campoFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(panelPodio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel11)
                                        .addGap(32, 32, 32)
                                        .addComponent(botonCargar, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(campoEventos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(campoId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(campoVIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(campoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)
                            .addComponent(campoPlatino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(panelPodio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(campoDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(campoGeneral, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(campoPuntaje, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(campoEliminatoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(botonCargar))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jLabel10)
                        .addComponent(campoHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(campoFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel14)
                        .addComponent(jLabel15)
                        .addComponent(campoDisciplinas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(campoEspacios, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonGuardar)
                    .addComponent(botonActualizar)
                    .addComponent(botonEliminar)
                    .addComponent(botonAnterior)
                    .addComponent(botonSiguiente)
                    .addComponent(botonLimpiar))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void botonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarActionPerformed

        if (campoNombre.getText().equals("")
                || campoDescripcion.getText().equals("")
                || campoHora.getText().equals("")
                || campoEliminatoria.getText().equals("")
                || campoPuntaje.getText().equals("")
                || campoVIP.getText().equals("")
                || campoPlatino.getText().equals("")
                || campoGeneral.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Ingrese los datos de la competencia");
        } else {
            nombre = campoNombre.getText();
            descripcion = campoDescripcion.getText();
            hora = campoHora.getText();
            cantidadAEliminatoria = Integer.parseInt(campoEliminatoria.getText());
            tipoPuntaje = campoPuntaje.getText();
            cantidadVip = Integer.parseInt(campoVIP.getText());
            cantidadPlatino = Integer.parseInt(campoPlatino.getText());
            cantidadGeneral = Integer.parseInt(campoGeneral.getText());
            boolean registrado = controladorCompetencia.guardar(nombre, descripcion, fecha, hora, imagenpodio, espacio,disciplina,evento, tipoPuntaje, cantidadVip, cantidadPlatino, cantidadGeneral, cantidadAEliminatoria);
            if (registrado) {
                JOptionPane.showMessageDialog(null, "Competencia registrada con exito");
                listaCompetencias = controladorCompetencia.buscarPorEvento(idEvento);
                inicializarTabla();
            } else {
                JOptionPane.showMessageDialog(null, "Competencia no se pudo registrar");
            }
        }

    }//GEN-LAST:event_botonGuardarActionPerformed

    private void botonActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonActualizarActionPerformed

        if (campoNombre.getText().equals("")
                || campoDescripcion.getText().equals("")
                || campoHora.getText().equals("")
                || campoEliminatoria.getText().equals("")
                || campoPuntaje.getText().equals("")
                || campoVIP.getText().equals("")
                || campoPlatino.getText().equals("")
                || campoGeneral.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Los campos obligatorios (*) no deben estar vacios");

        } else {
            nombre = campoNombre.getText();
            descripcion = campoDescripcion.getText();
            hora = campoHora.getText();
            cantidadAEliminatoria = Integer.parseInt(campoEliminatoria.getText());
            tipoPuntaje = campoPuntaje.getText();
            cantidadVip = Integer.parseInt(campoVIP.getText());
            cantidadPlatino = Integer.parseInt(campoPlatino.getText());
            cantidadGeneral = Integer.parseInt(campoGeneral.getText());
            boolean actualizado = controladorCompetencia.modificar(idCompetencia, nombre, descripcion, fecha, hora, imagenpodio, tipoPuntaje, cantidadVip, cantidadPlatino, cantidadGeneral, cantidadAEliminatoria);

            if (actualizado) {
                JOptionPane.showMessageDialog(null, "Competencia actualizada con exito");
            } else {
                JOptionPane.showMessageDialog(null, "Competencia no pudo ser actualizada");

                if (actualizado) {
                    JOptionPane.showMessageDialog(null, "Competencia actualizada con exito");
                } else {
                    JOptionPane.showMessageDialog(null, "Competencia no pudo ser actualizada");
                }

            }
        }
    }//GEN-LAST:event_botonActualizarActionPerformed

    private void botonEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonEliminarActionPerformed

        if (idCompetencia != 0) {
            boolean borrado = controladorCompetencia.borrar(idCompetencia);

            if (borrado) {
                JOptionPane.showMessageDialog(null, "Competencia eliminada con exito");
                limpiarFormulario();
                listaCompetencias = controladorCompetencia.buscarPorEvento(idEvento);
                inicializarTabla();
            } else {
                JOptionPane.showMessageDialog(null, "Competencia no se pudo eliminar");
            }
        } else {
            JOptionPane.showMessageDialog(null, "El evento no tiene competencias");
        }
    }//GEN-LAST:event_botonEliminarActionPerformed

    private void botonAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAnteriorActionPerformed

        if (indice > 0) {
            indice--;
            actualizarFormulario();
        }
    }//GEN-LAST:event_botonAnteriorActionPerformed

    private void botonSiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonSiguienteActionPerformed

        if (indice < listaCompetencias.size() - 1) {
            indice++;
            actualizarFormulario();
        }
    }//GEN-LAST:event_botonSiguienteActionPerformed

    private void botonLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonLimpiarActionPerformed

        limpiarFormulario();
    }//GEN-LAST:event_botonLimpiarActionPerformed

    private void campoEventosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoEventosActionPerformed
        // TODO add your handling code here:
        if (!listaEventos.isEmpty()) {
            idEvento = listaEventos.get(campoEventos.getSelectedIndex()).getIdevento();
            evento = controladorEvento.buscar(idEvento);
            inicializarListaCompetencias(idEvento);
        }
    }//GEN-LAST:event_campoEventosActionPerformed

    private void campoEspaciosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoEspaciosActionPerformed
        // TODO add your handling code here:
        if (!listaEspacios.isEmpty()) {
            idEspacio = listaEspacios.get(campoEspacios.getSelectedIndex()).getIdespacioDeportivo();
            espacio = controladorEspacioDeportivo.buscar(idEspacio);
        }
    }//GEN-LAST:event_campoEspaciosActionPerformed

    private void campoDisciplinasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoDisciplinasActionPerformed
        // TODO add your handling code here:
        if (!listaDisciplinas.isEmpty()) {
            idDisciplina = listaDisciplinas.get(campoDisciplinas.getSelectedIndex()).getIddisciplina();
            disciplina = controladorDisciplina.buscar(idDisciplina);
        }
    }//GEN-LAST:event_campoDisciplinasActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonActualizar;
    private javax.swing.JButton botonAnterior;
    private javax.swing.JButton botonCargar;
    private javax.swing.JButton botonEliminar;
    private javax.swing.JButton botonGuardar;
    private javax.swing.JButton botonLimpiar;
    private javax.swing.JButton botonSiguiente;
    private javax.swing.JTextField campoDescripcion;
    private javax.swing.JComboBox campoDisciplinas;
    private javax.swing.JTextField campoEliminatoria;
    private javax.swing.JComboBox campoEspacios;
    private javax.swing.JComboBox campoEventos;
    private com.toedter.calendar.JDateChooser campoFecha;
    private javax.swing.JTextField campoGeneral;
    private javax.swing.JTextField campoHora;
    private javax.swing.JTextField campoId;
    private javax.swing.JTextField campoNombre;
    private javax.swing.JTextField campoPlatino;
    private javax.swing.JTextField campoPuntaje;
    private javax.swing.JTextField campoVIP;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel panelPodio;
    private javax.swing.JTable tablaCompetencias;
    // End of variables declaration//GEN-END:variables
}
